Conditions | 1 |
Paths | 1 |
Total Lines | 90 |
Lines | 64 |
Ratio | 71.11 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict'; |
||
9 | describe('Mower', function() { |
||
10 | View Code Duplication | describe('start', function () { |
|
|
|||
11 | var grid = new Grid(new Position({x:5,y:5}, 'N')); |
||
12 | it('should stop at positon 1 3 N', function (done) { |
||
13 | var position = new Position({x:1,y:2}, 'N'), |
||
14 | mower = new Mower(0, grid, position, ['G','A','G','A','G','A','G','A','A']); |
||
15 | mower.start().then(function(mowerUpdated) { |
||
16 | expect(mowerUpdated.position).to.eql({ x:1, y:3, c:'N' }); |
||
17 | done(); |
||
18 | }); |
||
19 | }); |
||
20 | it('should stop at positon 4 1 E', function (done) { |
||
21 | var position = new Position({x:3,y:3}, 'E'), |
||
22 | mower = new Mower(0, grid, position, ['A','D','A','A','D','A','D','D','A']); |
||
23 | mower.start().then(function(mowerUpdated) { |
||
24 | expect(mowerUpdated.position).to.eql({ x:4, y:1, c:'E' }); |
||
25 | done(); |
||
26 | }); |
||
27 | }); |
||
28 | it('should stop at positon 5 4 N', function (done) { |
||
29 | var position = new Position({x:5,y:2}, 'S'), |
||
30 | mower = new Mower(0, grid, position, ['A','G','A','G','A','A','D','A','G','A']); |
||
31 | mower.start().then(function(mowerUpdated) { |
||
32 | expect(mowerUpdated.position).to.eql({ x:5, y:4, c:'N' }); |
||
33 | done(); |
||
34 | }); |
||
35 | }); |
||
36 | |||
37 | }); |
||
38 | View Code Duplication | describe('runStep', function () { |
|
39 | var grid = new Grid(new Position({x:10,y:10}, 'N')); |
||
40 | it('should stop at positon 3 2 E', function (done) { |
||
41 | var position = new Position({x:2,y:2}, 'E'); |
||
42 | var mower = new Mower(0, grid, position, ['A']); |
||
43 | mower.runStep(0,function(mowerUpdated) { |
||
44 | expect(mowerUpdated.position).to.eql({ x:3, y:2, c:'E' }); |
||
45 | done(); |
||
46 | }); |
||
47 | }); |
||
48 | it('should stop at positon 1 2 W', function (done) { |
||
49 | var position = new Position({x:2,y:2}, 'W'), |
||
50 | mower = new Mower(0, grid, position, ['A']); |
||
51 | mower.runStep(0,function(mowerUpdated) { |
||
52 | expect(mowerUpdated.position).to.eql({ x:1, y:2, c:'W' }); |
||
53 | done(); |
||
54 | }); |
||
55 | }); |
||
56 | it('should stop at positon 2 3 N', function (done) { |
||
57 | var position = new Position({x:2,y:2}, 'N'), |
||
58 | mower = new Mower(0, grid, position, ['A']); |
||
59 | mower.runStep(0,function(mowerUpdated) { |
||
60 | expect(mowerUpdated.position).to.eql({ x:2, y:3, c:'N' }); |
||
61 | done(); |
||
62 | }); |
||
63 | }); |
||
64 | it('should stop at positon 2 1 S', function (done) { |
||
65 | var position = new Position({x:2,y:2}, 'S'), |
||
66 | mower = new Mower(0, grid, position, ['A']); |
||
67 | mower.runStep(0,function(mowerUpdated) { |
||
68 | expect(mowerUpdated.position).to.eql({ x:2, y:1, c:'S' }); |
||
69 | done(); |
||
70 | }); |
||
71 | }); |
||
72 | |||
73 | }); |
||
74 | describe('isValid', function () { |
||
75 | var grid = new Grid(new Position({x:8,y:8}, 'N')), |
||
76 | position = new Position({x:3,y:3}, 'E'); |
||
77 | it('should throw an error when ID is not valid', function () { |
||
78 | expect(function() { |
||
79 | new Mower(false, grid, position, ['A']); |
||
80 | }).to.throwException(/Id is not valid/); |
||
81 | }); |
||
82 | it('should throw an error when GRID is not valid', function () { |
||
83 | expect(function() { |
||
84 | new Mower(0, false, position, ['A']); |
||
85 | }).to.throwException(/Grid is not valid/); |
||
86 | }); |
||
87 | it('should throw an error when POSITION is not valid', function () { |
||
88 | expect(function() { |
||
89 | new Mower(0, grid, false, ['A']); |
||
90 | }).to.throwException(/Position is not valid/); |
||
91 | }); |
||
92 | it('should throw an error when INSTRUCTIONS are not valid', function () { |
||
93 | expect(function() { |
||
94 | new Mower(0, grid, position, false); |
||
95 | }).to.throwException(/Instructions are not valid/); |
||
96 | }); |
||
97 | }); |
||
98 | }); |